package com.weishi.project.training.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import java.util.Arrays;
import com.weishi.project.training.domain.WorldAchievement;
import com.weishi.project.training.service.IWorldAchievementService;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.web.page.TableDataInfo;

/**
 * 世界成绩Controller
 */
@RestController
@RequestMapping("/training/worldAchievement")
public class WorldAchievementController extends BaseController {

    @Autowired
    private IWorldAchievementService worldAchievementService;

    /**
     * 查询世界成绩列表
     */
    @PreAuthorize("@ss.hasPermi('training:achievement:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorldAchievement worldAchievement) {
        startPage();
        List<WorldAchievement> list = worldAchievementService.selectWorldAchievementList(worldAchievement);
        return getDataTable(list);
    }

    /**
     * 导出世界成绩列表
     */
    @PreAuthorize("@ss.hasPermi('training:achievement:export')")
    @Log(title = "世界成绩", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorldAchievement worldAchievement) {
        List<WorldAchievement> list = worldAchievementService.selectWorldAchievementList(worldAchievement);
        ExcelUtil<WorldAchievement> util = new ExcelUtil<WorldAchievement>(WorldAchievement.class);
        return util.exportExcel(list, "achievement");
    }

    /**
     * 获取世界成绩详细信息
     */
    @PreAuthorize("@ss.hasPermi('training:achievement:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(worldAchievementService.getById(id));
    }

    /**
     * 新增世界成绩
     */
    @PreAuthorize("@ss.hasPermi('training:achievement:add')")
    @Log(title = "世界成绩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorldAchievement worldAchievement) {
        worldAchievementService.save(worldAchievement);
        return AjaxResult.success();
    }

    /**
     * 修改世界成绩
     */
    @PreAuthorize("@ss.hasPermi('training:achievement:edit')")
    @Log(title = "世界成绩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorldAchievement worldAchievement) {
        worldAchievementService.updateById(worldAchievement);
        return AjaxResult.success();
    }

    /**
     * 删除世界成绩
     */
    @PreAuthorize("@ss.hasPermi('training:achievement:remove')")
    @Log(title = "世界成绩", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        worldAchievementService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
    
}